/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__ending_judge.c                                  */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/30 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include <pop3/pop3.h>
#include "frsutl.h"
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frreport_comm.h"
#include "../../../src/module/pop3/config.h"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

extern int __ending_judge(char *p_payload, unsigned int ui_payload_len);

static void case1(void)
{
    char *p_payload = NULL;
    unsigned int ui_payload_len = 0;

    int i_ret = 2;

    i_ret = __ending_judge(p_payload, ui_payload_len);

    CU_ASSERT_EQUAL(i_ret, 0);

    return;
}

static void case2(void)
{
    int i_ret = 0;
    char *p_payload = NULL;
    unsigned int ui_payload_len = 29;

    p_payload = (char *)"+OK Name is a valid mailbox\r\n";

    i_ret = 2;

    i_ret = __ending_judge(p_payload, ui_payload_len);

    CU_ASSERT_EQUAL(i_ret, 1);

    return;
}

static void case3(void)
{
    int i_ret = 0;
    char *p_payload = NULL;
    unsigned int ui_payload_len = 38;

    p_payload = (char *)"+OK scan listing follows\r\n";

    i_ret = 2;

    i_ret = __ending_judge(p_payload, ui_payload_len);

    CU_ASSERT_EQUAL(i_ret, 0);

    return;
}

static void case4(void)
{
    int i_ret = 0;
    char *p_payload = NULL;
    unsigned int ui_payload_len = 38;

    p_payload = (char *)"1 56519\r\n.\r\n";

    i_ret = 2;

    i_ret = __ending_judge(p_payload, ui_payload_len);

    CU_ASSERT_EQUAL(i_ret, 1);

    return;
}

static void case5(void)
{
    int i_ret = 0;
    char *p_payload = NULL;
    unsigned int ui_payload_len = 38;

    p_payload = (char *)"\r\n\r\n.\r\n";

    i_ret = 2;

    i_ret = __ending_judge(p_payload, ui_payload_len);

    CU_ASSERT_EQUAL(i_ret, 1);

    return;
}

int add_suite__ending_judge()
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __ending_judge()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL ||
        CU_add_test(pSuite, "case4", case4) == NULL ||
        CU_add_test(pSuite, "case5", case5) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}